<template>
	<view class="page" :style="{height:windowHeight+'px'}">
		<view class="head">
			<view class="head-content">
				<view class="page-head-img">
					<image class="location" src="../../../static/dafaulthead2.png" v-if="detail.avatarUrl == '' ">
					</image>
					<image class="location" :src="detail.avatarUrl" mode="aspectFill" title="头像" v-else></image>
				</view>
				<view class="allintegral">
					总积分
					<view class="integral" v-if="total == 0">
						00.00
					</view>
					<view class="integral" v-else>
						{{total}}
					</view>
				</view>
			</view>

			<view class="head-rule" @click="gotoPage('/pages/user/shoppingmall/rule/rule')">
				<view class="rule-item">
					<image src="../../../static/rule1.png"></image>
				</view>
				<view>
					<text>积分规则</text>
				</view>
			</view>
		</view>
		<view class="conversion">
			<text class="one ">
				一 积分
			</text>
			<text>
				兑好礼 <text class="one"> 一</text>
			</text>
		</view>
		<!-- <view class="vip-card" v-for="(item,index) of shop">
			<view class="vip-image">
				<image :src="item.shop_iamge"></image>
			</view>
			<view>
				<view class="vip-content">
					<text>{{item.shop_name}}</text>
					<text>{{item.shop_describe}}</text>
					<text>{{item.shop_time}}</text>
					<text>{{item.shop_integral}}积分</text>
				</view>
				<view class="vip-use" @click="exchange(index)">
					立即兑换
				</view>
			</view>
		</view> -->
		<!-- <view class="vip-card" v-for="n in 3">
			<view class="vip-image">
				<image src="../../../static/record-bg.png"></image>
			</view>
			<view>
				<view class="vip-content">
					<text>健康理疗养生会馆服务卡</text>
					<text>3次免费理疗体验</text>
					<text>900积分</text>
				</view>
				<view class="vip-use" @click="exchange($event)">
					立即兑换
				</view>
			</view>
		</view> -->
		<view class="vip-card" v-for="(item,index) of shopData">
			<view class="vip-image">
				<image :src="item.shop_iamge"></image>
			</view>
			<view>
				<view class="vip-content">
					<text>{{item.shop_name}}</text>
					<text class="shop_explain">{{item.shop_explain}}</text>
					<text>{{item.shop_time}}</text>
					<text>{{item.shop_integral }}积分</text>
				</view>
				<!-- <view class="vip-use" @click="exchange(index)">
					立即兑换
				</view> -->
			</view>
		</view>
		<!-- 没有记录 -->
		<!-- <view class="null d-c-c p30" v-if="shopData.length == 0">
			<text class="iconfont icon-wushuju"></text>
			<text class="cont">亲，暂无相关记录哦</text>
		</view> -->
		<!-- <uni-load-more v-else :loadingType="loadingType"></uni-load-more> -->
		<!-- <view class="developing" v-if="developing">
			正在开发当中，请尽情期待... ...
		</view> -->
		<view>
			<view class="yy" v-if="isShow" @click="close"></view>

			<!-- <view class="notIntegral" v-if="">
				您的积分不足。
			</view> -->
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				shop: [{
						shop_id: 1,
						shop_iamge: '../../../static/record-bg.png',
						shop_name: '健康理疗养生会馆服务卡',
						shop_describe: '3次免费理疗体验',
						shop_integral: '900',
						shop_time: '2020-2-2到2023-2-2',
						shop_exchange: '立即兑换',
					},
					{
						shop_id: 2,
						shop_iamge: '../../../static/record-bg.png',
						shop_name: '2健康理疗养生会馆服务卡',
						shop_describe: '4次免费理疗体验',
						shop_integral: '800',
						shop_time: '2020.2.2-2023.2.2',
						shop_exchange: '立即兑换',
					},
				],
				detail: {
					avatarUrl: '', //头像
				},
				// shopData2:{
				// 	integral:'00.00'
				// },
				shopData: [],
				windowHeight: '',
				isShow: false,
				allIntegral: '00.00',
				total: 0, //总积分 
				developing: true,

			};
		},
		onLoad() {
			this.getDatainfo();
			this.getShopData();

			uni.getSystemInfo({
				success: (res) => {
					this.windowHeight = res.windowHeight;
				}
			});
		},
		onShow() {
			this.getTotalData();
		},
		methods: {
			/*获取总积分数据*/
			getTotalData() {
				let self = this;
				uni.showLoading({
					title: '加载中'
				});
				self._get(
					'user.index/my_money', {

					},
					function(data) {
						self.total = data.data.list.integral
						//this.loading = true;
						uni.hideLoading();
					}
				);
			},
			/* 立即兑换 */
			exchange(idx) {
				let self = this;
				let a1 = self.total;
				let a2 = self.shopData[idx].shop_integral;
				if (a1 < a2) {
					uni.showToast({
						title: '您的积分不足。',
						duration: 2000,
						icon: 'none'
					})
					return;
				}
				let formdata = {};
				formdata.shop_id = self.shopData.shop_id;
				uni.showLoading({
					title: '正在兑换',
				});
				self._post(
					'product.product/get_product',
					formdata,
					result => {
						if (result.code == 1) {
							uni.showToast({
								title: '成功！',
								duration: 2000,
								icon: 'none'
							});
							//self.gotoPage('/pages/user/record/record');
						}
						// 执行回调函数
						// uni.navigateBack();
					},

					false,
					() => {
						uni.hideLoading();
					}
				)
			},
			/*获取个人数据*/
			getDatainfo() {
				let self = this;
				uni.showLoading({
					title: '加载中'
				});
				self._get('user.index/detail', {}, function(res) {
					//console.log(res);
					self.detail = res.data.userInfo;
					self.loadding = false;
				});
			},
			/*获取商城数据*/
			getShopData() {
				let self = this;
				uni.showLoading({
					title: '加载中'
				});
				self._get('product.product/lists', {}, function(res) {
					//console.log(res)
					self.shopData = res.data.list;
					// self.total = res.data.list.total;
					self.loadding = false;
				});
			},
			gotoPage(path) {
				let self = this;
				if (path.startsWith('/')) {
					uni.navigateTo({
						url: path
					});
				} else {
					self[path]();
				}
			},
		}
	}
</script>

<style lang="scss">
	.page {
		width: 100%;
		height: 1200rpx;
		background-color: #F4F4F4;
	}

	.head {
		height: 260rpx;
		width: 100%;
		background-image: url(../../../static/shopping-bg1.png);
		overflow: hidden;
		position: relative;
	}

	.head-content {
		display: flex;
		flex-direction: row;
		align-items: center;
		margin-top: 30rpx;
	}

	.page-head-img {
		width: 100rpx;
		height: 100rpx;
		margin: 10rpx 40rpx;
		border: 1rpx solid #ffffff;
		border-radius: 50%;
		margin-top: 40rpx;
	}

	.location {
		border-radius: 50%;
	}

	.allintegral {
		margin-top: 6rpx;
		margin-left: -26rpx;
	}

	.integral {
		margin-top: 16rpx;
		margin-left: 20rpx;
		font-weight: 700;
		font-size: 36rpx;
	}

	.head-rule {
		position: absolute;
		right: 0rpx;
		top: 50%;
		margin-top: -30rpx;
		width: 260rpx;
		background-color: #ffd361;
		height: 60rpx;
		line-height: 60rpx;
		border-radius: 100rpx 0 0 100rpx;
		display: flex;
		flex-direction: row;
	}

	.rule-item {
		width: 60rpx;
		height: 60rpx;
		border-radius: 50%;
		margin-right: 30rpx;
	}

	.rule-item image {
		width: 100%;
		height: 100%;
	}

	.conversion {
		width: 100%;
		height: 100rpx;
		text-align: center;
		line-height: 100rpx;
		font-size: 30rpx;
		letter-spacing: 4rpx;
	}

	.one {
		color: #ff7b2e;
		margin-left: 10rpx;
	}


	.vip-card {
		padding: 40rpx 20rpx;
		position: relative;
		display: flex;
		flex-direction: row;
		border-bottom: 4rpx solid #e7e7e7;
		background-color: #FFFFFF;
	}

	.vip-card:last-child {
		border: none;
	}

	.vip-image {
		width: 260rpx;
		height: 180rpx;
		border-radius: 20rpx;
		margin-right: 30rpx;
	}

	.vip-image image {
		width: 260rpx;
		//height: 100%;
		border-radius: 16rpx;
	}

	.vip-content {
		margin-top: 6rpx;
		display: flex;
		flex-direction: column;
	}

	.vip-content text:nth-child(2) {
		margin-top: 10rpx;
		color: #7e7a75;
		//margin-bottom: 60rpx;
	}

	.vip-content text:nth-child(3) {
		margin-top: 10rpx;
		color: #7e7a75;
		margin: 10rpx 0 20rpx;
	}

	.vip-content text:nth-child(4) {
		color: #f9ac10;
	}

	.vip-use {
		width: 160rpx;
		height: 60rpx;
		text-align: center;
		line-height: 60rpx;
		border: 2rpx solid #f9ac10;
		border-radius: 100rpx;
		color: #f9ac10;
		position: absolute;
		bottom: 20rpx;
		right: 20rpx;
	}

	// .null{
	// 	position: fixed;
	// 	top: 0;
	// 	left: 0;
	// 	z-index: 999;
	// }
	.yy {
		width: 100%;
		height: 100%;
		position: fixed;
		top: 0;
		left: 0;
		background-color: rgba(0, 0, 0, 0.6);
		z-index: 998;
	}

	.shop_explain {
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 2;
		overflow: hidden;
	}

	.developing {
		width: 100%;
		height: 100%;
		line-height: 600rpx;
		background-color: #FFFFFF;
		position: fixed;
		top: 0rpx;
		left: 0;
		text-align: center;
		font-size: 30rpx;
		z-index: 999;
	}
</style>
